package com.aier.common.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.aier.common.dao.ICommonDAO;
import com.aier.common.entity.Message;
import com.aier.common.entity.MessageRowMapper;
import com.aier.common.service.IMessageService;

@Component("messageService")
public class MessageServiceImpl_J implements IMessageService {

    @Resource(name = "commonDao")
    private ICommonDAO commonDao;

    public void setCommonDao(ICommonDAO commonDao) {
        this.commonDao = commonDao;
    }
    
    @Override
    public Message deleteMessage(String phone, String code) {
        
        Message message = (Message)commonDao.listByObject("select * from message where phone=? and content=?",
                new Object[] {phone,code}, new MessageRowMapper());
        if (null != message) {
            commonDao.update("delete from message where phone=?",new Object[]{phone});
        }
        return message;
    }

    @Override
    public int insertMessage(String phone, String code) {
        if (commonDao.update("insert into message(phone,content) value(?,?)",
                new Object[] {phone,code})>0) {
            return 1;
        } else {
            return 0;
        }
    }

}
